package com.lgl.allpeoplevent.ventIndex.controller;

import com.lgl.allpeoplevent.base.controller.BaseController;
import com.lgl.allpeoplevent.ventIndex.service.VentCommentService;
import com.lgl.allpeoplevent.ventIndex.service.VentService;
import com.lgl.scsapi.system.model.PageData;
import com.lgl.scsapi.vent.model.VentComment;
import com.lgl.scsapi.vent.model.VentUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 吐槽评论controller
 */
@Slf4j
@RestController
@RequestMapping(value="/ventComment")
public class VentCommentController extends BaseController {
    @Autowired
    private VentCommentService ventCommentService;
    @Autowired
    private VentService ventService;

    /**
     * 保存吐槽评论数据
     */
    @RequestMapping(value="/saveVentComment")
    public Object saveVent(@ModelAttribute VentComment vc){
        if (vc == null){
            return -2;
        }
        VentUser ventUser = getSessionUser();
        vc.setUserId(ventUser.getUserId());
        int row = ventCommentService.saveVentComment(vc);
        long commentId = vc.getId();
        ventService.commentTotalAddOne(String.valueOf(vc.getVentId()));
        vc = null;
        Map<String,Long> resultMap = new HashMap<>(4);
        resultMap.put("id",commentId);
        resultMap.put("status",(long)row);
        return resultMap;
    }
    //保存点赞数据
    @RequestMapping(value="/saveCommentLike")
    public Object saveCommentLike(@RequestParam Long commentId){
        PageData clPageData = new PageData(4);
        VentUser ventUser = getSessionUser();
        if (ventUser == null){
            clPageData.put("status", -1);
            return clPageData;
        }
        clPageData.put("commentId", commentId);
        clPageData.put("likeUserId", ventUser.getUserId());
        ventCommentService.saveCommentLike(clPageData);
        ventCommentService.likeTotalAddOne(commentId);
        PageData resultPd = new PageData(2);
        resultPd.put("status",0);
        return resultPd;
    }
}